package com.wteam.dragon.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wteam.dragon.shop.pojo.bean.HotProductHome;
import com.wteam.dragon.shop.service.HotProductHomeService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.basebean.vo.PageVo;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 陈晓辉
 * @Date 2021/3/25 20:55
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "热销推荐管理")
@RequestMapping("hotProductHome")
public class HotProductHomeController {
    private final HotProductHomeService hotProductHomeService;

    @Log("批量添加商品到热销推荐")
    @ApiOperation("批量添加商品到热销推荐")
    @PostMapping("addHotProductHome")
    @PreAuthorize("@el.check('addHotProductHome')")
    public ResultMessage addHotProductHome(@RequestParam List<Long> ids){
        return hotProductHomeService.addHotProductHome(ids);
    }

    @Log("批量删除热销推推荐")
    @ApiOperation("批量删除热销推荐")
    @DeleteMapping("delHotProductHome")
    @PreAuthorize("@el.check('delHotProductHome')")
    public ResultMessage delHotProductHome(@RequestParam List<Long> ids){
        return hotProductHomeService.delHotProductHome(ids);
    }

    @Log("更改排序")
    @ApiOperation("更改排序")
    @PutMapping("editHotProductHome")
    @PreAuthorize("@el.check('editHotProductHome')")
    public ResultMessage editHotProductHome(Long id, Long sort){
        return hotProductHomeService.editHotProductHome(id, sort);
    }

    @Log("分页获得热销推荐")
    @ApiOperation("分页获得热销推荐")
    @PutMapping("pageHotProductHome")
    @PreAuthorize("@el.check('pageHotProductHome')")
    public ResultMessage pageHotProductHome(PageVo<HotProductHome> pageVo, String productName, String recommendStatus){
        Page<HotProductHome> page = BeanUtil.fromPage(pageVo);
        return hotProductHomeService.pageHotProductHome(page, productName, recommendStatus);
    }

    @Log("批量推荐和批量取消推荐")
    @ApiOperation("批量推荐和批量取消推荐")
    @PutMapping("editHotProductHomeStatus")
    @PreAuthorize("@el.check('editHotProductHomeStatus')")
    public ResultMessage editHotProductHomeStatus(@RequestParam List<Long> ids, Integer status){
        return hotProductHomeService.editHotProductHomeStatus(ids, status);
    }

}
